﻿using NearAop;
using System;
using System.Collections.Generic;
using System.Text;

namespace CS
{
    [AddProxyInterface(typeof(Proxy5), typeof(IMyInterface1))]
    [AddProxyInterface(typeof(Proxy6), typeof(IMyInterface2))]
    class T08_手动初始化代理字段
    {
        //直接使用字段类型
        [SetProxySource]
        readonly Proxy5 proxy5 = new Proxy5("接口1");

        //直接使用特性指定的类型
        [SetProxySource(typeof(Proxy6))]
        readonly object proxy6 = new Proxy6("接口2");
    }


    class Proxy5 : IMyInterface1
    {
        private readonly string value;

        public Proxy5(string value) => this.value = value;

        public void ShowMsg1()
        {
            Console.WriteLine(value);
        }
    }

    class Proxy6 : IMyInterface2
    {
        private readonly string value;

        public Proxy6(string value) => this.value = value;

        public void ShowMsg2()
        {
            Console.WriteLine(value);
        }
    }
}
